package com.eric.nioclient.service.packet;

import java.nio.charset.Charset;

import io.netty.buffer.ByteBuf;

/**
 * Created by eric on 2017/11/16.
 */
public class UserOutPacket extends Packet {
    public String reason ; // 原因

    public UserOutPacket(String reason){
        this.reason = reason;
    }

    public UserOutPacket(){}

    public void writePacketMsg(ByteBuf buf) {
        writeUTF8(buf,reason);
    }

    public void readFromBuff(ByteBuf buf) {
        reason = readUTF8(buf);
    }

    public PacketType getPacketType() {
        return PacketType.UserOut;
    }

    public void execPacket() {

    }

    @Override
    protected int getBodyLength() {
        int length = 0 ;
        byte[] bb = reason.getBytes(Charset.forName("utf-8"));
        length += bb.length + 4;

        return length;
    }
}
